/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package businesscard.DAO;

import bc.entity.Nhomnganh;
import bc.util.HibernateUtil;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

/**
 *
 * @author Welcome
 */
public class NhomnganhDAO {
    private Session session;

    public NhomnganhDAO() {
        SessionFactory factory = HibernateUtil.getSessionFactory();
        this.session = factory.getCurrentSession();
    }
    public Nhomnganh[] getAllNhomnganh()  {     
        try {
            session.getTransaction().begin();
            String sql = "from Nhomnganh";
            Query query = session.createQuery(sql);
            List result=query.list();
           Nhomnganh[] cityList = new Nhomnganh[result.size()];
            result.toArray(cityList);
            session.flush();
            session.getTransaction().commit();
            return cityList;
        } catch (Exception e) {
            if (session.getTransaction().isActive()) {
                session.getTransaction().rollback();
            }
            e.printStackTrace();
        }
        return null;

    }
}
